﻿using CSRedis;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

namespace AdminSystem.WebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "v1")]
    public class BlogController : ControllerBase
    {
        private readonly CSRedisClient cSRedisClient;

            //...........

            //发邮件
            //Thread.Sleep(TimeSpan.FromSeconds(30));
        public BlogController(CSRedisClient cSRedisClient)
        {
            this.cSRedisClient = cSRedisClient;
        }

        [HttpGet]
        public async Task<IActionResult> Send(string Title,string Content)
        {
            //保存到数据库


            //保存Redis
            /*cSRedisClient.LPush(nameof(BlogController), new {
                Id = Guid.NewGuid().ToString("N"),
                Title = Title,
                Content = Content
            });*/

            await cSRedisClient.PublishAsync("channel.1", JsonConvert.SerializeObject(new
            {
                Id = Guid.NewGuid().ToString("N"),
                Title = Title,
                Content = Content
            }));

            return Ok();
        }

        /// <summary>
        /// CI/CD测试
        /// </summary>
        /// <returns></returns>
        [HttpPut("/api/test/cicd/aaaaa")]
        public IActionResult Test()
        {
            return Ok();
        }
    }
}
